{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "afba3a9e",
   "metadata": {},
   "source": [
    "____________________\n",
    "\n",
    "* 时间：2022/11/14/week13\n",
    "* python学习记录\n",
    "\n",
    "_____________________\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e33e1320",
   "metadata": {},
   "source": [
    "# Head First Python 练习"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2877223e",
   "metadata": {},
   "source": [
    "## 1.Lists"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "86803a8e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "# A-1\n",
    "vowels = ['a','e','i','o','u']\n",
    "word = \"Milliways\"\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        print(letter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ffa84765",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "['i', 'i', 'a']"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# A-2\n",
    "vowels = ['a','e','i','o','u']\n",
    "word = \"Milliways\"\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        print(letter)\n",
    "        found.append(letter)\n",
    "found"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "84f937e2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c']\n"
     ]
    }
   ],
   "source": [
    "# A-3\n",
    "phrase = \"Don't panic\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "2f945a39",
   "metadata": {},
   "outputs": [],
   "source": [
    "plist.remove('D')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "54969c3e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c']"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "fe72b340",
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(3):\n",
    "    plist.pop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "a0d877cb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['o', 'n', \"'\", 't', ' ', 'p', 'a']"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "1badf358",
   "metadata": {},
   "outputs": [],
   "source": [
    "plist.remove(\"'\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "00805a37",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['o', 'n', 't', ' ', 'p', 'a']"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "f63c43c4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'a'"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plist[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "7dde647a",
   "metadata": {},
   "outputs": [],
   "source": [
    "plist.insert(3,plist[-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "05d3b564",
   "metadata": {},
   "outputs": [],
   "source": [
    "plist.insert(2,plist[-3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "2ac2e6d0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['o', 'n', ' ', 't', 'a', ' ', 'p', 'a']"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "4033368e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'a'"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plist.pop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "7072e082",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['o', 'n', ' ', 't', 'a', ' ', 'p']"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "38827319",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "' '"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plist.pop(-2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "73eebbd9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['o', 'n', ' ', 't', 'a', 'p']"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "c31e3bcb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "['o', 'n', 't', ' ', 'p', 'a']\n",
      "['o', 'n', 't', ' ', 'a', 'p']\n",
      "['o', 'n', ' ', 't', 'a', 'p']\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'on tap'"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# A-3 整理 （列表的方法）\n",
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "for i in range(4):\n",
    "    plist.pop()\n",
    "plist.pop(0)\n",
    "plist.remove(\"'\")\n",
    "print(plist)\n",
    "plist.extend([plist.pop(),plist.pop()])\n",
    "print(plist)\n",
    "plist.insert(2,plist.pop(3))\n",
    "print(plist)\n",
    "# 列表元素的合并：''.join()\n",
    "''.join(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "37f96aee",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n"
     ]
    }
   ],
   "source": [
    "# A-4 列表的切片和取值\n",
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "f20a2b1a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'on tap'"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "''.join([plist[1],plist[2],plist[5],plist[4],plist[-5],plist[-6]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9daccf04",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
